import { defineStore } from 'pinia'
import tabsStoreCreater from './tabsStore'
import DuUtil from '../utils/DuUtil'

const cacheStore = defineStore({
  id: 'cacheState',

  state: () => ({
    cacheNameArr: [],
  }),
  getters: {},
  actions: {
    addCacheName(name) {
      this.cacheNameArr.push(name)
    },
    removeCacheName(name) {
      DuUtil.arrayRemove(this.cacheNameArr, name)
    },
    resetCacheName() {
      const tabsStore = tabsStoreCreater()
      const cacheNamesNew = []
      tabsStore.tabs.forEach((tab) => {
        if (tab.cache) {
          cacheNamesNew.push(tab.path)
        }
      })
      this.cacheNameArr = cacheNamesNew
    },
  },
})
export default cacheStore
